package com.ruoyi.project.men.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.men.domain.MenProductTypeParamDO;
import com.ruoyi.project.men.service.MenProductTypeParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 核心产品-产品类型-参数Controller
 *
 * @author long
 * @date 2021-04-15
 */
@RestController
@RequestMapping("/men/menProductParam")
public class MenProductTypeParamController extends BaseController
{
	@Autowired
	private MenProductTypeParamService menProductTypeParamService;

	/**
	 * 查询核心产品-产品类型-参数列表
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('men:menProductParam:list')")
	@GetMapping("/list")
	public TableDataInfo list(MenProductTypeParamDO menProductTypeParam)
	{
		startPage();
		Map<String, Object> stringObjectMap = BeanUtil.beanToMap(menProductTypeParam);
		stringObjectMap.put("delFlag","0");
		stringObjectMap.put("sort","ca_at");
		stringObjectMap.put("order","desc");
		List<MenProductTypeParamDO> list = menProductTypeParamService.list(stringObjectMap);
		return getDataTable(list);
	}

	/**
	 * 导出核心产品-产品类型-参数列表
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('men:menProductParam:export')")
	@Log(title = "核心产品-产品类型-参数", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult export(MenProductTypeParamDO menProductTypeParam)
	{
		Map<String, Object> stringObjectMap = BeanUtil.beanToMap(menProductTypeParam);
		List<MenProductTypeParamDO> list = menProductTypeParamService.list(stringObjectMap);
		ExcelUtil<MenProductTypeParamDO> util = new ExcelUtil<MenProductTypeParamDO>(MenProductTypeParamDO.class);
		return util.exportExcel(list, "menProductParam");
	}

	/**
	 * 获取核心产品-产品类型-参数详细信息
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('men:menProductParam:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") String id)
	{
		return AjaxResult.success(menProductTypeParamService.get(id));
	}

	/**
	 * 新增核心产品-产品类型-参数
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('men:menProductParam:add')")
	@Log(title = "核心产品-产品类型-参数", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody MenProductTypeParamDO menProductTypeParam)
	{
		menProductTypeParam.setId(IdUtil.simpleUUID());
		menProductTypeParam.setDelFlag(0);
		menProductTypeParam.setCaAt(new Date());
		return toAjax(menProductTypeParamService.save(menProductTypeParam));
	}

	/**
	 * 修改核心产品-产品类型-参数
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('men:menProductParam:edit')")
	@Log(title = "核心产品-产品类型-参数", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody MenProductTypeParamDO menProductTypeParam)
	{
		menProductTypeParam.setUpAt(new Date());
		return toAjax(menProductTypeParamService.update(menProductTypeParam));
	}

	/**
	 * 删除核心产品-产品类型-参数
	 */
	@ResponseBody
	@PreAuthorize("@ss.hasPermi('men:menProductParam:remove')")
	@Log(title = "核心产品-产品类型-参数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable String[] ids)
	{
		if(ids.length>0){
			for (String string : ids) {
				MenProductTypeParamDO menProductTypeParam = menProductTypeParamService.get(string);
				menProductTypeParam.setDelFlag(1);
				menProductTypeParam.setUpAt(new Date());
				menProductTypeParamService.update(menProductTypeParam);
			}
		}
		return toAjax(ids.length);
		//return toAjax(menProductTypeParamService.deleteMenProductTypeParamByIds(ids));
	}
}
